<template>
	<view class="header">
		<text>热销产品</text>
		<view class="" @click="bindService">
			<image src="../../static/service-black.png" mode=""></image>
		</view>
	</view>
	<view class="hot-product-list">
		<view class="produce" v-for="(item,index) in hotProductData" :key="index" >
			<image src="../../static/card_productslist.png" class="product-bg" mode=""></image>
			<view class="pc">
				<view class="product-header">
					<image :src="item.cover" mode=""></image>
					<text class="product-title">{{item.name}} {{ item.lockDays}}天</text>
				</view>
				<view class="right">
					
					<text class="note">每日返息，到期还本</text>
					
					<view class="tips" style="margin-top: 0;">
						<text >稳健理财 | 低风险</text>
						
					</view>
				</view>
				<view class="footer">
					<view class="fitem" v-for="(item,index) in item.limitMoney" :key="index">
						
						<view class="f1">
							<text class="f-t">第{{index+1}}期</text>
							<text class="status act" v-if="item.status=='hot_selling'">热销中</text>
							<text class="status" v-if="item.status=='not_open'">未开放</text>
							<text class="status" v-if="item.status=='sold_out'">已售罄</text>
						</view>
						<view class="tips">
							<text>限量{{item.sumLimitMoney}}U</text>
							<text class="line"></text>
								<text>剩余{{item.inventoryMoney}}U</text>
						</view>
						<view class="f2">
							<view class="f3">
								<view class="price">
									<text class="amount">{{(item.interest * 100).toFixed(2)}}</text>
								
									<text class="unit">%</text>
								</view>
								<text class="day">日利率</text>
							</view>
							<button plain @click="bindProductInfo(item)" v-if="item.status=='hot_selling'">立即购买</button>
						</view>
						
					</view>
					
				</view>
				
			</view>
	
	
	
		</view>
	</view>
	<image src="../../static/empty.png" mode="widthFix" style="width: 348rpx;display: block;margin:400rpx auto;" v-if="emptyState"></image>
	<uni-tabBar current="2"></uni-tabBar>
</template>

<script setup>
	import {
		onShow,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		productList
	} from '@/util/api.js'
	import {
		ref
	} from 'vue';
	onReachBottom(()=>{
		queryParams.value.pageNum++
		getProductList()
		console.log("....")
	})
	const emptyState = ref(false)
	const queryParams = ref({
		pageSize: 10,
		pageNum: 1
	})
	const hotProductData = ref([])
	const bindService = ()=>{
		uni.navigateTo({
			url:"/pages/webViewService/webViewService"
		})
	}
	onShow(() => {
		uni.hideTabBar({
			animation: false
		})
		getProductList()
	})
	const getProductList = async () => {
		const result = await productList(queryParams.value)
		if(queryParams.value.pageNum==1){
			if(result.data.records.length==0){
				emptyState.value = true
			}else{
				emptyState.value = false
			}
			hotProductData.value = result.data.records
		}else{
			hotProductData.value = hotProductData.value.concat(result.data.records)
		}
	}
	// 产品详情
	const bindProductInfo = (item)=>{
		
		
		uni.navigateTo({
			url:"/pages/productInfo/productInfo?id="+item.id+'&pid='+item.productId
		})
	}
</script>

<style lang="scss">
	page {
		background: #F6F7F9;
	}

	.hot-product-list {
		margin: 0 40rpx 52rpx;


		.produce {
			width: 613rpx;
			height: 384rpx;
			background: #FFFFFF;
			position: relative;
			border-radius: 23rpx;
			margin-bottom: 30rpx;
			padding: 30rpx;
			box-shadow: 0px 15rpx 38rpx 0px rgba(0, 0, 0, 0.06);
			display: flex;
			align-items: center;
			.product-bg{
				position: absolute !important;
				width: 673rpx;
				height: 444rpx;
				left: 0;
				top: 0;
			}
			.pc{
				width: 100%;
				position: relative;
			}
			.right {
				display: flex;
				justify-content: space-between;
			}
			.product-header{
				display: flex;
				align-items: center;
				
				margin-bottom: 20rpx;
				>image{
					display: block;
					width: 38rpx;
					height: 38rpx;
					margin-right: 12rpx;
				}
			}
			.product-title {
				display: block;
				color: #313646;
				font-weight: bold;
				font-size: 31rpx;

				
			}

			.note {
				width: 231rpx;
				display: block;
				height: 42rpx;
				background: #FEF6E9;
				border-radius: 8rpx;
				color: #FF984D;
				font-size: 24rpx;
				line-height: 42rpx;



			}

			.tips {
				display: flex;
				align-items: center;
				
				// margin-top:24rpx ;

				text {
					color: #989AA2;
					font-size: 23rpx;
				}

				.line {
					display: block;
					width: 2rpx;
					height: 28rpx;
					background: #989AA2;
					margin: 0 20rpx;
				}
			}

			.footer {

				width: 100%;
				overflow-y: scroll;
				display: flex;
				margin-top: 20rpx;
				.fitem{
					margin-right: 15px;
					// width: 298rpx;
					padding: 0 20rpx;
					height: 267rpx;
					min-width: 320rpx;
					min-height: 267rpx;
					background: #FFFFFF;
					border-radius: 23rpx;
					border: 2rpx solid #EBF0F4;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
				}
				.f1{
					display: flex;
					align-items: center;
					
					margin-top: 30rpx;
					.ft{
						color: #313646;
						font-size: 28rpx;
						font-weight: bold;
					}
					.status{
						display: block;
						margin-left: 10rpx;
						width: 81rpx;
						height: 35rpx;
						background: #EAECF3;
						border-radius: 8rpx;
						line-height: 35rpx;
						text-align: center;
						color: #989AA2;
						font-size: 20rpx;
					}
					.act{
						background: #FFECEB;
						color: #FF2F22;
					}
				}
				.f2{
					display: flex;
					align-items: flex-end;
					justify-content: space-between;
					
					margin-bottom: 20rpx;
					.f3{
						.price {
						
							.amount {
								color: #FF2F22;
								font-size: 40rpx;
								font-weight: bold;
							}
						
							.unit {
								color: #FF2F22;
								font-size: 28rpx;
							}
						}
					}
					button {
						width: 131rpx;
						min-width: 131rpx;
						height: 65rpx;
						background: rgba(67, 120, 255, 0.2);
						border-radius: 42rpx;
						color: #316BFF;
						font-size: 23rpx;
						font-weight: bold;
						padding: 0;
						margin: 0;
						border: none;
						line-height: 65rpx;
						
					}
				}
				

				

				.day {
					color: #989AA2;
					font-size: 23rpx;
					display: block;

				}

			}
		}

	}

	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-top: 100rpx;
		margin: 0 38rpx 38rpx;
		overflow: hidden;

		text {
			display: block;
			color: #313646;
			font-weight: bold;
			font-size: 38rpx;
		}

		view {
			width: 69rpx;
			height: 69rpx;
			background: rgba(204, 212, 231, 0.2);
			border-radius: 23rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			image {
				display: block;
				width: 38rpx;
				height: 38rpx;
			}

		}
	}
</style>